var anhui = require('./srcretJSON/anhui.json');
var aomen = require('./srcretJSON/aomen.json');
var beijing = require('./srcretJSON/beijing.json');
var chongqing = require('./srcretJSON/chongqing.json');
var fujian = require('./srcretJSON/fujian.json');
var gansu = require('./srcretJSON/gansu.json');
var guangdong = require('./srcretJSON/guangdong.json');
var guangxi = require('./srcretJSON/guangxi.json');
var guizhou = require('./srcretJSON/guizhou.json');
var hainan = require('./srcretJSON/hainan.json');
var hebei = require('./srcretJSON/hebei.json');
var henan = require('./srcretJSON/henan.json');
var heilongjiang = require('./srcretJSON/heilongjiang.json');
var hubei = require('./srcretJSON/hubei.json');
var hunan = require('./srcretJSON/hunan.json');
var jilin = require('./srcretJSON/jilin.json');
var jiangsu = require('./srcretJSON/jiangsu.json');
var jiangxi = require('./srcretJSON/jiangxi.json');
var liaoning = require('./srcretJSON/liaoning.json');
var neimenggu = require('./srcretJSON/neimenggu.json');
var ningxia = require('./srcretJSON/ningxia.json');
var qinghai = require('./srcretJSON/qinghai.json');
var shandong = require('./srcretJSON/shandong.json');
var shanxi1 = require('./srcretJSON/shanxi1.json');
var shanxi = require('./srcretJSON/shanxi.json');
var shanghai = require('./srcretJSON/shanghai.json');
var sichuan = require('./srcretJSON/sichuan.json');
var taiwan = require('lib/geoJSON/tai_wan_geo.json');
var tianjin = require('./srcretJSON/tianjin.json');
var xizang = require('./srcretJSON/xizang.json');
var xianggang = require('./srcretJSON/xianggang.json');
var xinjiang = require('./srcretJSON/xinjiang.json');
var yunnan = require('./srcretJSON/yunnan.json');
var zhejiang = require('./srcretJSON/zhejiang.json');

var decode = require('./decode');
var cache = {};

function getOriginalJSON(cnCode) {
  if (!cnCode) {
    return null;
  }

  var relation = null;
  switch (cnCode) {
    case '340000': // 安徽
      relation = anhui;
      break;
    case '820000': // 澳门
      relation = aomen;
      break;
    case '110000': // 北京
      relation = beijing;
      break;
    case '500000': // 重庆
      relation = chongqing;
      break;
    case '350000': // 福建
      relation = fujian;
      break;
    case '620000': // 甘肃省
      relation = gansu;
      break;
    case '440000': // 广东省
      relation = guangdong;
      break;
    case '450000': // 广西壮族自治区
      relation = guangxi;
      break;
    case '520000': // 贵州省
      relation = guizhou;
      break;
    case '460000': // 海南省
      relation = hainan;
      break;
    case '130000': // 河北省
      relation = hebei;
      break;
    case '410000': // 河南省
      relation = henan;
      break;
    case '230000': // 黑龙江省
      relation = heilongjiang;
      break;
    case '420000': // 湖北省
      relation = hubei;
      break;
    case '430000': // 湖南省
      relation = hunan;
      break;
    case '220000': // 吉林省
      relation = jilin;
      break;
    case '320000': // 江苏省
      relation = jiangsu;
      break;
    case '360000': // 江西省
      relation = jiangxi;
      break;
    case '210000': // 辽宁省
      relation = liaoning;
      break;
    case '150000': // 内蒙古自治区
      relation = neimenggu;
      break;
    case '640000': // 宁夏回族自治区
      relation = ningxia;
      break;
    case '630000': // 青海省
      relation = qinghai;
      break;
    case '370000': // 山东省
      relation = shandong;
      break;
    case '610000': // 陕西省
      relation = shanxi1;
      break;
    case '140000': // 山西省
      relation = shanxi;
      break;
    case '310000': // 上海市
      relation = shanghai;
      break;
    case '510000': // 四川省
      relation = sichuan;
      break;
    case '710000': // 台湾
      relation = taiwan;
      break;
    case '120000': // 天津市
      relation = tianjin;
      break;
    case '540000': // 西藏自治区
      relation = xizang;
      break;
    case '810000': // 香港特别行政区
      relation = xianggang;
      break;
    case '650000': // 新疆维吾尔自治区
      relation = xinjiang;
      break;
    case '530000': // 云南省
      relation = yunnan;
      break;
    case '330000': // 浙江省
      relation = zhejiang;
      break;
    default:
      break;
  }

  return relation;
} // getOriginalJSON

module.exports = function getJSON(cnCode) {
  var result = cache[cnCode]
  if (result) {
    return result;
  }

  var originalJson = getOriginalJSON(cnCode);
  if (originalJson) {
    cache[cnCode] = result = decode(originalJson);
  }

  return result;
} // getJSON
